Skip to content

Method: renderMapAt(Coordinates, int)

1: /*
2: * *************************************************************************************************************************************************************
3: *
4: * blueMarine III: Semantic DAM
5: * http://tidalwave.it/projects/bluemarine3
6: *
7: * Copyright (C) 2024 - 2025 by Tidalwave s.a.s. (http://tidalwave.it)
8: *
9: * *************************************************************************************************************************************************************
10: *
11: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
12: * You may obtain a copy of the License at
13: *
14: * http://www.apache.org/licenses/LICENSE-2.0
15: *
16: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
17: * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
18: *
19: * *************************************************************************************************************************************************************
20: *
21: * git clone https://bitbucket.org/tidalwave/bluemarine3-src
22: * git clone https://github.com/tidalwave-it/bluemarine3-src
23: *
24: * *************************************************************************************************************************************************************
25: */
26: package it.tidalwave.bluemarine3.mapviewer.impl.javafx;
27:
28: import jakarta.annotation.Nonnull;
29: import jakarta.inject.Inject;
30: import java.nio.file.Path;
31: import javafx.fxml.FXML;
32: import javafx.scene.control.Button;
33: import javafx.scene.control.Label;
34: import javafx.scene.control.Slider;
35: import javafx.scene.layout.AnchorPane;
36: import it.tidalwave.bluemarine3.mapviewer.spi.MapViewerPresentation;
37: import it.tidalwave.geo.Coordinates;
38: import it.tidalwave.geo.GeoTrack;
39: import it.tidalwave.geo.RectangularArea;
40: import it.tidalwave.mapviewer.OpenTopoMapTileSource;
41: import it.tidalwave.mapviewer.javafx.MapView;
42: import it.tidalwave.ui.javafx.JavaFXBinder;
43: import it.tidalwave.util.ui.UserNotification;
44: import static it.tidalwave.bluemarine3.mapviewer.impl.javafx.Converters.*;
45:
46: /***************************************************************************************************************************************************************
47: *
48: * @stereotype Presentation
49: * @author Fabrizio Giudici
50: *
51: **************************************************************************************************************************************************************/
52: public class JavaFXMapViewerPresentationDelegate implements MapViewerPresentation
53: {
54: private static final String TRACK_OVERLAY_NAME = "track";
55:
56: @FXML
57: private AnchorPane apAnchorPane;
58:
59: @FXML
60: private Slider slZoom;
61:
62: @FXML
63: private Button btZoomIn;
64:
65: @FXML
66: private Button btZoomOut;
67:
68: @FXML
69: private Button btReframe;
70:
71: @FXML
72: private Label lbCoordinates;
73:
74: private MapView mapView;
75:
76: @Inject
77: private JavaFXBinder binder;
78:
79: /***********************************************************************************************************************************************************
80: * {@inheritDoc}
81: **********************************************************************************************************************************************************/
82: @Override
83: public void initialize (@Nonnull final Bindings bindings, @Nonnull final Path cacheFolder)
84: {
85: mapView = new MapView(MapView.options().withCacheFolder(cacheFolder));
86: mapView.setTileSource(new OpenTopoMapTileSource());
87: AnchorPane.setLeftAnchor(mapView, 0.0);
88: AnchorPane.setRightAnchor(mapView, 0.0);
89: AnchorPane.setTopAnchor(mapView, 0.0);
90: AnchorPane.setBottomAnchor(mapView, 0.0);
91: apAnchorPane.getChildren().add(mapView);
92: mapView.setRecenterOnDoubleClick(true);
93: slZoom.minProperty().bind(mapView.minZoomProperty());
94: slZoom.maxProperty().bind(mapView.maxZoomProperty());
95: // slZoom.setBlockIncrement(0.1);
96: binder.bind(btZoomIn, bindings.zoomIn);
97: binder.bind(btZoomOut, bindings.zoomOut);
98: binder.bind(btReframe, bindings.reframe);
99: binder.bindBidirectionally(bindings.zoom, slZoom.valueProperty());
100: binder.bindBidirectionally(bindings.zoom, mapView.zoomProperty()); // FIXME: bindings.zoom can go out of the zoomProperty range
101: binder.bind(bindings.coordinatesUnderMouse, mapView.coordinatesUnderMouseProperty(), Converters::toCoordinates);
102: }
103:
104: /***********************************************************************************************************************************************************
105: * {@inheritDoc}
106: **********************************************************************************************************************************************************/
107: @Override
108: public void renderMapAt (@Nonnull final Coordinates center, final int zoom)
109: {
110: mapView.setCenter(toMapCoordinates(center));
111: mapView.setZoom(zoom);
112: }
113:
114: /***********************************************************************************************************************************************************
115: * {@inheritDoc}
116: **********************************************************************************************************************************************************/
117: @Override
118: public void renderTrack (@Nonnull final GeoTrack track, @Nonnull final RectangularArea area)
119: {
120: mapView.fitArea(toMapArea(area));
121: mapView.removeAllOverlays();
122: mapView.addOverlay(TRACK_OVERLAY_NAME, new TrackOverlayCreator(track));
123: }
124:
125: /***********************************************************************************************************************************************************
126: * {@inheritDoc}
127: **********************************************************************************************************************************************************/
128: @Override
129: public void removeTrack()
130: {
131: mapView.removeOverlay(TRACK_OVERLAY_NAME);
132: }
133:
134: /***********************************************************************************************************************************************************
135: * {@inheritDoc}
136: **********************************************************************************************************************************************************/
137: @Override
138: public void renderCoordinates (@Nonnull final String coordinates)
139: {
140: lbCoordinates.setText(coordinates);
141: }
142:
143: /***********************************************************************************************************************************************************
144: * {@inheritDoc}
145: **********************************************************************************************************************************************************/
146: public void fitTo (@Nonnull final RectangularArea area)
147: {
148: mapView.fitArea(toMapArea(area));
149: }
150:
151: /***********************************************************************************************************************************************************
152: * {@inheritDoc}
153: **********************************************************************************************************************************************************/
154: @Override
155: public void notifyError (@Nonnull final UserNotification error)
156: {
157: binder.showInModalDialog(error);
158: }
159: }